import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author deity
 * @version 1.0
 * @date 2020/11/8 23:56
 */
public class ParallelLambda {
    public static void main(String[] args) {
        //整数列表
        List<Integer> lists = new ArrayList<>();
        //增加数据
        for (int i = 0; i < 1000; i++) {
            lists.add(i);
        }


        //串行stream
        List<Integer> list2 = new ArrayList<>();
        lists.stream().forEach(x -> list2.add(x));
        System.out.println("list2=" + list2.size() + "  lists=" + lists.size());
        //并行stream
        List<Integer> list3 = new ArrayList<>();
        lists.parallelStream().forEach(x -> list3.add(x));
        System.out.println("list3=" + list3.size() + "  lists=" + lists.size());

        //使用终端操作,保证信息完整
        List<Integer> list4 = lists.parallelStream().collect(Collectors.toList());
        System.out.println(list4.size());
    }
}
